﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ClassLibrary;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Globalization;

namespace Forms
{
    public partial class DemmandConfirm : UIForm
    {
        //定义一个结构体用来记录要传递给DemmandForm界面的参数值
        public struct ValueToDemmandForm
        {
            public string DemmandId;
            public string DemmandStatus;
            public string DemmandDeadline;
            public string DemmandAddr;
            public string DemmandType;
        }

        public ValueToDemmandForm valueToDemmandForm;

        public DemmandConfirm(string content, User user)
        {
            valueToDemmandForm = new ValueToDemmandForm();
            InitializeComponent();
            ID.Text = Guid.NewGuid().ToString();
            //Content.Text = content;
            Status.Text = "正在创建";
            //Date.Text = DateTime.Now.ToString();
            SenderID.Text = user.UserID;
            DemmandAddress.Text = user.UserAddress;//默认是设定的地址
            Color userColor = MainForm.MainForm.userColor;
            UIStyles.InitColorful(userColor, Color.White);
        }

        /*//判断用户输入的日期格式是否正确
        private void DemmandDeadline_Validating1(object? sender, CancelEventArgs e)
        {
            string userInput = SelectDateTime.Text;
            DateTime parsedTime;

            // 使用 TryParseExact 方法验证用户输入是否为指定的时间格式（年月日时分秒）
            if (!DateTime.TryParseExact(userInput, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out parsedTime))
            {
                e.Cancel = true; // 取消输入
                MessageBox.Show("请输入有效的年月日时分秒格式 (yyyy-MM-dd HH:mm)", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                SelectDateTime.Focus(); // 让用户重新输入
            }
        }*/

        private void SendDemmand_Click(object sender, EventArgs e)
        {
            //输入信息的判断
            if (DemmandAddress.Text == "" || DemmandAddress.Text == null || DemmandType.SelectedItem == null)
            {
                UIMessageBox.Show("请完善信息后再提交！");
            }
            //输入信息无误，绑定传回主界面的结构体参数值
            valueToDemmandForm.DemmandId = ID.Text;
            valueToDemmandForm.DemmandStatus = Status.Text;
            valueToDemmandForm.DemmandDeadline = SelectDateTime.Text;
            valueToDemmandForm.DemmandAddr = DemmandAddress.Text;
            valueToDemmandForm.DemmandType = DemmandType.SelectedItem.ToString();


            this.Close();
        }

        private void DemmandAddress_TextChanged(object sender, EventArgs e)
        {
        }

        private void DemmandDeadline_TextChanged(object sender, EventArgs e)
        {

        }

        private void SelectDateTime_ValueChanged(object sender, DateTime value)
        {

        }

        private void Status_Click(object sender, EventArgs e)
        {

        }
    }
}
